﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MVCTest.Controllers
{
    public class StaticsAttribute : ActionFilterAttribute
    {
        private Stopwatch w;

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            w = new Stopwatch();
            w.Start();
        }

        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            w.Stop();
        }

        public override void OnResultExecuted(ResultExecutedContext filterContext)
        {
            var e = w.ElapsedMilliseconds;
            //filterContext.HttpContext.Response.Write("<p style='font-size:10px'>该请求后台执行时间:" + e + "ms</p>");
        }
    }
}
